<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="乡镇" prop="town">
        <el-input
          v-model="queryParams.town"
          placeholder="请输入乡镇"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆类型" prop="carType">
        <el-select v-model="queryParams.carType" placeholder="请选择车辆类型" clearable>
          <el-option
            v-for="dict in dict.type.car_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="车牌号码" prop="carNumber">
        <el-input
          v-model="queryParams.carNumber"
          placeholder="请输入车牌号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车主姓名" prop="carOwnerName">
        <el-input
          v-model="queryParams.carOwnerName"
          placeholder="请输入车主姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="carOwnerPhone">
        <el-input
          v-model="queryParams.carOwnerPhone"
          placeholder="请输入联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证号码" prop="carOwnerIdCard" label-width="100px">
        <el-input
          v-model="queryParams.carOwnerIdCard"
          placeholder="请输入身份证号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="驾驶人姓名" prop="driverName" label-width="100px">
        <el-input
          v-model="queryParams.driverName"
          placeholder="请输入驾驶人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="driverPhone">
        <el-input
          v-model="queryParams.driverPhone"
          placeholder="请输入联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="驾驶人居住地址" prop="driverAddress" label-width="120px">-->
<!--        <el-input-->
<!--          v-model="queryParams.driverAddress"-->
<!--          placeholder="请输入驾驶人居住地址"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="是否纳入赋色管理" prop="colorManage">-->
<!--        <el-select v-model="queryParams.colorManage" placeholder="请选择是否纳入赋色管理" clearable>-->
<!--          <el-option-->
<!--            v-for="dict in dict.type.sys_yes_no"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="赋色管理种类" prop="colorType">-->
<!--        <el-select v-model="queryParams.colorType" placeholder="请选择赋色管理种类" clearable>-->
<!--          <el-option-->
<!--            v-for="dict in dict.type.color_type"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="包乡镇（街道）责任人" prop="dutyTownName">-->
<!--        <el-input-->
<!--          v-model="queryParams.dutyTownName"-->
<!--          placeholder="请输入包乡镇（街道）责任人"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="联系电话" prop="dutyTownPhone">-->
<!--        <el-input-->
<!--          v-model="queryParams.dutyTownPhone"-->
<!--          placeholder="请输入联系电话"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="包村（社区）责任人" prop="dutyVillageName">-->
<!--        <el-input-->
<!--          v-model="queryParams.dutyVillageName"-->
<!--          placeholder="请输入包村（社区）责任人"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="联系电话" prop="dutyVillagePhone">-->
<!--        <el-input-->
<!--          v-model="queryParams.dutyVillagePhone"-->
<!--          placeholder="请输入联系电话"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="包户责任人" prop="dutyHuName">-->
<!--        <el-input-->
<!--          v-model="queryParams.dutyHuName"-->
<!--          placeholder="请输入包户责任人"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="联系电话" prop="dutyHuPhone">-->
<!--        <el-input-->
<!--          v-model="queryParams.dutyHuPhone"-->
<!--          placeholder="请输入联系电话"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="queryAndPop">查询并弹窗</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['moto:info:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['moto:info:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['moto:info:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['moto:info:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['moto:info:import']"
        >导入</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="序号" align="center" prop="infoId" />-->
      <el-table-column label="乡镇" align="center" prop="town" />
      <el-table-column label="车辆类型" align="center" prop="carType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.car_type" :value="scope.row.carType"/>
        </template>
      </el-table-column>
      <el-table-column label="车牌号码" align="center" prop="carNumber" />
      <el-table-column label="车主姓名" align="center" prop="carOwnerName" />
      <el-table-column label="联系电话" align="center" prop="carOwnerPhone" />
      <el-table-column label="驾驶人姓名" align="center" prop="driverName" />
      <el-table-column label="联系电话" align="center" prop="driverPhone" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleView(scope.row)"
            v-hasPermi="['moto:info:edit']"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['moto:info:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['moto:info:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改摩托基础信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="图片" prop="imgUrl">
          <image-upload v-model="form.imgUrl" limit="1"/>
        </el-form-item>
        <el-row>
          <el-col :span="7">
            <el-form-item label="乡镇" prop="town">
              <el-input v-model="form.town" placeholder="请输入乡镇" />
            </el-form-item>
          </el-col>
          <el-col :span="7">
          <el-form-item label="车辆类型" prop="carType">
            <el-select v-model="form.carType" placeholder="请选择车辆类型">
              <el-option
                v-for="dict in dict.type.car_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
          </el-col>
          <el-col :span="10">
          <el-form-item label="车牌号码" prop="carNumber">
            <el-input v-model="form.carNumber" placeholder="请输入车牌号码" />
          </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="7">
            <el-form-item label="车主姓名" prop="carOwnerName">
              <el-input v-model="form.carOwnerName" placeholder="请输入车主姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="联系电话" prop="carOwnerPhone">
              <el-input v-model="form.carOwnerPhone" placeholder="请输入联系电话" />
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="身份证号码" prop="carOwnerIdCard" label-width="90px">
              <el-input v-model="form.carOwnerIdCard" placeholder="请输入身份证号码" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="7">
            <el-form-item label="驾驶人姓名" prop="driverName" label-width="95px">
              <el-input v-model="form.driverName" placeholder="请输入驾驶人姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="联系电话" prop="driverPhone">
              <el-input v-model="form.driverPhone" placeholder="请输入联系电话" />
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="身份证号码" prop="driverIdCard" label-width="90px">
              <el-input v-model="form.driverIdCard" placeholder="请输入身份证号码" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="驾驶人居住地址" prop="driverAddress" label-width="110px">
          <el-input v-model="form.driverAddress" placeholder="请输入驾驶人居住地址"  />
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="是否纳入赋色管理" prop="colorManage" label-width="140px">
              <el-select v-model="form.colorManage" placeholder="请选择是否纳入赋色管理">
                <el-option
                  v-for="dict in dict.type.sys_yes_no"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="赋色管理种类" prop="colorType" label-width="140px">
              <el-select v-model="form.colorType" placeholder="请选择赋色管理种类">
                <el-option
                  v-for="dict in dict.type.color_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12" >
            <el-form-item label="包乡镇（街道）责任人" prop="dutyTownName" label-width="160px">
              <el-input v-model="form.dutyTownName" placeholder="请输入包乡镇（街道）责任人" />
            </el-form-item>
          </el-col>
          <el-col :span="12" >
            <el-form-item label="联系电话" prop="dutyTownPhone" label-width="140px">
              <el-input v-model="form.dutyTownPhone" placeholder="请输入联系电话" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="包村（社区）责任人" prop="dutyVillageName" label-width="140px">
              <el-input v-model="form.dutyVillageName" placeholder="请输入包村（社区）责任人" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="dutyVillagePhone" label-width="140px">
              <el-input v-model="form.dutyVillagePhone" placeholder="请输入联系电话" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="包户责任人" prop="dutyHuName" label-width="140px">
              <el-input v-model="form.dutyHuName" placeholder="请输入包户责任人" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="dutyHuPhone" label-width="140px">
              <el-input v-model="form.dutyHuPhone" placeholder="请输入联系电话" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="驾驶证" prop="license" label-width="140px">
          <el-select v-model="form.license" placeholder="请选择驾驶证">
            <el-option
              v-for="dict in dict.type.driver_license_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="title" :visible.sync="viewOpen" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="图片" prop="imgUrl">
          <image-upload v-model="form.imgUrl" limit="1"/>
        </el-form-item>
        <el-row>
          <el-col :span="7">
            <el-form-item label="乡镇" prop="town">
              <el-input disabled v-model="form.town" placeholder="请输入乡镇" />
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="车辆类型" prop="carType">
              <el-select disabled v-model="form.carType" placeholder="请选择车辆类型">
                <el-option
                  v-for="dict in dict.type.car_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="车牌号码" prop="carNumber">
              <el-input disabled v-model="form.carNumber" placeholder="请输入车牌号码" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="7">
            <el-form-item label="车主姓名" prop="carOwnerName">
              <el-input disabled v-model="form.carOwnerName" placeholder="请输入车主姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="联系电话" prop="carOwnerPhone">
              <el-input disabled v-model="form.carOwnerPhone" placeholder="请输入联系电话" />
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="身份证号码" prop="carOwnerIdCard" label-width="90px">
              <el-input disabled v-model="form.carOwnerIdCard" placeholder="请输入身份证号码" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="7">
            <el-form-item label="驾驶人姓名" prop="driverName" label-width="95px">
              <el-input disabled v-model="form.driverName" placeholder="请输入驾驶人姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="联系电话" prop="driverPhone">
              <el-input disabled v-model="form.driverPhone" placeholder="请输入联系电话" />
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="身份证号码" prop="driverIdCard" label-width="90px">
              <el-input disabled v-model="form.driverIdCard" placeholder="请输入身份证号码" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="驾驶人居住地址" prop="driverAddress" label-width="110px">
          <el-input disabled v-model="form.driverAddress" placeholder="请输入驾驶人居住地址"  />
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="是否纳入赋色管理" prop="colorManage" label-width="140px">
              <el-select disabled v-model="form.colorManage" placeholder="请选择是否纳入赋色管理">
                <el-option
                  v-for="dict in dict.type.sys_yes_no"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="赋色管理种类" prop="colorType" label-width="140px">
              <el-select disabled v-model="form.colorType" placeholder="请选择赋色管理种类">
                <el-option
                  v-for="dict in dict.type.color_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12" >
            <el-form-item label="包乡镇（街道）责任人" prop="dutyTownName" label-width="160px">
              <el-input disabled v-model="form.dutyTownName" placeholder="请输入包乡镇（街道）责任人" />
            </el-form-item>
          </el-col>
          <el-col :span="12" >
            <el-form-item label="联系电话" prop="dutyTownPhone" label-width="140px">
              <el-input disabled v-model="form.dutyTownPhone" placeholder="请输入联系电话" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="包村（社区）责任人" prop="dutyVillageName" label-width="140px">
              <el-input disabled v-model="form.dutyVillageName" placeholder="请输入包村（社区）责任人" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="dutyVillagePhone" label-width="140px">
              <el-input disabled v-model="form.dutyVillagePhone" placeholder="请输入联系电话" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="包户责任人" prop="dutyHuName" label-width="140px">
              <el-input disabled v-model="form.dutyHuName" placeholder="请输入包户责任人" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="dutyHuPhone" label-width="140px">
              <el-input disabled v-model="form.dutyHuPhone" placeholder="请输入联系电话" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="驾驶证" prop="license" label-width="140px">
          <el-select disabled v-model="form.license" placeholder="请选择驾驶证">
            <el-option
              v-for="dict in dict.type.driver_license_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input disabled v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cancelView">确定</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo } from "@/api/moto/info";
import {getToken} from "@/utils/auth";

export default {
  name: "Info",
  dicts: ['color_type', 'sys_yes_no', 'car_type', 'driver_license_type'],
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 摩托基础信息表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      viewOpen:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        town: null,
        carType: null,
        carNumber: null,
        carOwnerName: null,
        carOwnerPhone: null,
        carOwnerIdCard: null,
        driverIdCard: null,
        driverName: null,
        driverPhone: null,
        driverAddress: null,
        colorManage: null,
        colorType: null,
        dutyTownName: null,
        dutyTownPhone: null,
        dutyVillageName: null,
        dutyVillagePhone: null,
        dutyHuName: null,
        dutyHuPhone: null,
        license: null,
        imgUrl: null,
        status: null,
      },
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/moto/info/importData"
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        town: [
          { required: true, message: "乡镇不能为空", trigger: "blur" }
        ],
        carType: [
          { required: true, message: "车辆类型不能为空", trigger: "change" }
        ],
        carNumber: [
          { required: true, message: "车牌号码不能为空", trigger: "blur" }
        ],
        carOwnerName: [
          { required: true, message: "车主姓名不能为空", trigger: "blur" }
        ],
        carOwnerPhone: [
          { required: true, message: "车主电话不能为空", trigger: "blur" }
        ],
        driverName: [
          { required: true, message: "驾驶人姓名不能为空", trigger: "blur" }
        ],
        driverPhone: [
          { required: true, message: "驾驶人电话不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    // this.getList();
  },
  methods: {
    /** 查询摩托基础信息列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询摩托基础信息列表 */
    getListAndPop() {
      listInfo(this.queryParams).then(response => {
        let lengthData = response.rows.length;
        if (lengthData === 1) {
          getInfo(response.rows[0].infoId).then(response => {
            this.form = response.data;
            this.viewOpen = true;
            this.title = "查看摩托基础信息";
          });
        }
        // this.infoList = response.rows;
        // this.total = response.total;
        // this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    cancelView() {
      this.viewOpen = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        infoId: null,
        town: null,
        carType: null,
        carNumber: null,
        carOwnerName: null,
        carOwnerPhone: null,
        carOwnerIdCard: null,
        driverIdCard: null,
        driverName: null,
        driverPhone: null,
        driverAddress: null,
        colorManage: null,
        colorType: null,
        dutyTownName: null,
        dutyTownPhone: null,
        dutyVillageName: null,
        dutyVillagePhone: null,
        dutyHuName: null,
        dutyHuPhone: null,
        license: null,
        imgUrl: null,
        remark: null,
        status: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    queryAndPop() {
      this.queryParams.pageNum = 1;
      this.getListAndPop();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.infoId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加摩托基础信息";
    },
    /** 修改按钮操作 */
    handleView(row) {
      this.reset();
      const infoId = row.infoId || this.ids
      getInfo(infoId).then(response => {
        this.form = response.data;
        this.viewOpen = true;
        this.title = "查看摩托基础信息";
      });
    },
    handleUpdate(row) {
      this.reset();
      const infoId = row.infoId || this.ids
      getInfo(infoId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改摩托基础信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.infoId != null) {
            updateInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const infoIds = row.infoId || this.ids;
      this.$modal.confirm('是否确认删除摩托基础信息编号为"' + infoIds + '"的数据项？').then(function() {
        return delInfo(infoIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('moto/info/export', {
        ...this.queryParams
      }, `info_${new Date().getTime()}.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    handleImport() {
      this.upload.title = "摩托车数据导入";
      this.upload.open = true;
    },
    submitFileForm() {
      this.$refs.upload.submit();
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('moto/info/importTemplate', {
      }, `moto_template_${new Date().getTime()}.xlsx`)
    },
  }
};
</script>
